#!/usr/bin/env python
import os,sys,re

def combine():
    files=map(lambda idx:'mingqi_click_201309%s.txt' % (idx if idx>=10 else '0%s' % idx),range(27))
    f=open('mingqi_click_201309.txt','w')
    keys='post_click,new_post_click,mingqi_zhuanqu_click,pn1_post_click'.split(',')
    for _file in files:
        if not os.path.exists(_file):continue
        date=re.search(r'_(\d{8})',_file).group(1)
        info=dict(zip(keys,[0,0,0,0]))
        for line in open(_file,'r'):
            k,v=line.strip().split('\t')
            if k in info:
                info[k]=v
        f.write('\t'.join([date]+map(lambda key:str(info[key]),keys))+'\n')
    f.close()
 
if __name__ == '__main__':
    combine()
